<template>
    <div>
        <el-table :data="datas" style="width: 100%" max-height="400" border>
            <el-table-column fixed label="序号" width="150">
                <template #default="scopes">
                    {{ scopes.$index+1 }}
                </template>
            </el-table-column>
            <el-table-column fixed prop="part" label="部门" width="300" />
            <el-table-column prop="isupload" label="领导班子报告" width="300" />
            <el-table-column prop="reporttime" label="上传时间" width="200" disabled/>
            <el-table-column fixed="right" label="操作" width="300">
                <template #default="scope">
                    <div>
                        <el-upload
                                :show-file-list="false"
                                :before-upload="beforeUpload"
                                :on-success="onSuccess"
                                accept=".docx"
                                :on-error="onError"
                                :disabled="importDisabled"
                                style="display: inline-flex;margin-right: 10px;"
                                :action="'http://localhost:8080/data/importL?uid='+scope.row.uid">
                            <el-button size="small" :disabled="importDisabled" type="success">
                                <el-icon class="el-icon--left"><Upload /></el-icon>{{importDataText}}
                                <div slot="tip" class="el-upload__tip">只能上传docx文件</div>
                            </el-button >
                        </el-upload>
                        <el-button size="small" type="success" :disabled="scope.row.isupload !== '已上传'" @click="look(scope.row)">预览</el-button>
                        <el-button type="success" @click="changeState(scope.row, '审核通过...师傅正在赶来的路上')" :disabled="scope.row.isupload !== '待审核'">审核通过</el-button>
                        <el-button type="danger" @click="changeState(scope.row, '审核不通过')" :disabled="scope.row.isupload !== '待审核'">审核不通过</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 20, 50]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script setup>
import { ref,onMounted } from 'vue'
import {ElMessage} from 'element-plus'
import { get,post } from '@/utils/request.js'
import { reactive } from 'vue'
import * as echarts from 'echarts'
import {userStore} from '@/stores/counter.js'
import moment from 'moment'

const importDataText=ref('上传领导班子报告')
const importDisabled=ref(false)
const store=userStore()
const datas=ref([])
const score=ref([])
const score1=ref([])
const score2=ref([])
const classi=ref([])
 const currentPage=ref(1)
 const pageSize=ref(5)
 const total=ref(10)

onMounted(()=>{
currentPage.value=1
findAll()
})

const findAll=()=>{
post('/user/getPageL',{
currentPage:currentPage.value,
pageSize:pageSize.value
},(message)=>{
let a=[]
a=message.rows
for(let i=0;i<a.length;i++){
if(a[i].isupload==='已上传'){
a[i].reporttime=moment(a[i].reporttime).format('YYYY-MM-DD hh:mm:ss')
}else if(a[i].isupload==='待审核')a[i].reporttime=moment(a[i].reporttime).format('YYYY-MM-DD hh:mm:ss')
else a[i].reporttime=''
}
datas.value=a
total.value=message.totalCount
},(message)=>{
ElMessage.warning(message)
})
}

const onError=()=>{
                importDataText.value = '上传领导班子报告';
                this.importDisabled.value = false;
                this.$message.success("上传失败！");
            }

const onSuccess=()=> {
            	// 成功后文本修改为原来的导入数据
                importDataText.value = '上传领导班子报告';
                // 将上传组件改为允许使用
                importDisabled.value = false;
                // 调用刷新数据的方法
                findAll();
                // message 弹出消息
                ElMessage.success("导入成功！");
            }

const beforeUpload=()=> {
            	// 将文本修改为正在导入
                importDataText.value = '正在上传';
                // 将其上传组件暂时禁用
                importDisabled.value = true;
            }

const handleSizeChange=(val)=> {
          pageSize.value=val
          findAll()
        console.log(`每页 ${val} 条`);
      }
const handleCurrentChange=(val)=> {
      currentPage.value=val
      findAll()
        console.log(`当前页: ${val}`);
      }

const look=(row)=>{
window.open('http://localhost:8080/user/lookL?uid='+row.uid)

}


const changeState=(row, state)=> {
if(state=='审核通过...师傅正在赶来的路上'){
post('/user/checksuccess1',{
uid:row.uid
},(message)=>{
findAll()
datas.value=[]
ElMessage.success(message)
},(message)=>{
ElMessage.warning(message)
})
}else{
post('/user/checkfailure1',{uid:row.uid},(message)=>{
findAll()
datas.value=[]
ElMessage.success(message)
},(message)=>{
ElMessage.warning(message)
})
}
    }
</script>
<style scoped>
</style>